package com.caimiao.miao.page.master.system.bluetooth;

import android.content.Context;
import android.os.Build;
import android.view.View;

import com.caimiao.miao.R;
import com.caimiao.miao.interfaces.IBaseAdapter;
import com.caimiao.miao.library.bluetooth.BTDevice;

import java.util.List;
import java.util.UUID;

public class BluetoothAdapter extends IBaseAdapter<BTDevice> {

    public BluetoothAdapter(Context context, List<BTDevice> dataLists) {
        super(context, dataLists);
    }

    public void add(BTDevice device) {
        mDataList.add(device);
        notifyDataSetChanged();
    }

    @Override
    protected int getItemLayout() {
        return R.layout.item_device;
    }

    @Override
    protected BaseHolder createHolder(View convertView) {
        return new BaseHolder(convertView);
    }

    @Override
    protected void setLogic(int position, View convertView, BaseHolder holder) {
        BTDevice device = mDataList.get(position);
        holder.setText(R.id.itemDeviceTvName, device.getName());
        holder.setText(R.id.itemDeviceTvAddress, device.getAddress());
        holder.setText(R.id.itemDeviceTvState, String.valueOf(device.getState()));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            holder.setText(R.id.itemDeviceTvType, String.valueOf(device.getType()));
        }
        StringBuilder sb = new StringBuilder();
        List<UUID> uuid = device.getUuid();
        int length = uuid == null ? 0 : uuid.size();
        for (int i = 0; i < length; i++) {
            if (sb.length() > 0) sb.append("\n");
            sb.append(uuid.get(i).toString());
        }
        holder.setText(R.id.itemDeviceTvUuid, sb.toString());


    }
}
